from flask import Blueprint, request
from conn_mysql import ConnectMysql
from .access_token_notify import access_token_verify_func


app_add_dirver = Blueprint('app_add_dirver', 'api')

@app_add_dirver.route('/app_add_dirver', methods=['POST'])
def add_dirver():

    dirver_name = request.form.get('dirver_name')
    dirver_phone = request.form.get('dirver_phone')

    if not all([dirver_name, dirver_phone]):

        return {
            'status' : -1,
            'errorCode': 1,
            'errorMsg': "检查参数，有参数为空",
            'resultBody': None,
        }


    sql = "SELECT * FROM dirver WHERE dirver_name=%s"
    sql_ = "SELECT * FROM dirver WHERE dirver_phone=%s"
    sql__ = "INSERT INTO dirver(dirver_name, dirver_phone) VALUES (%s, %s)"
    with ConnectMysql() as c:

        if any([c.select_one(sql, (dirver_name,)), c.select_one(sql_, (dirver_phone,))]):

            return {
            'status' : -1,
            'errorCode': 102,
            'errorMsg': "手机号或姓名被占用",
            'resultBody': None,
        }

        c.insert_info(sql__, (dirver_name, dirver_phone))

    return {
        'status' : 1,
        'errorCode': None,
        'errorMsg': None,
        'resultBody': "添加成功",
    }
    





    

